import React from 'react';
import {Link} from 'react-router';
import Table, {
    setColumnKeys,
    yesRender
} from '../_/table';
import redux from '../_/redux';
import _name, {_title} from './dev';

/*function getTree(nodes, pid = null, level = 0) {
 const children = _.filter(nodes, i => i.Pid === pid);
 return _.flatMap(children, i => {
 const node = u({level, Id: i.Id + ''}, i);
 return [node, ...getTree(nodes, i.Id, level + 1)];
 });
 }*/

const types = {1: '病历打印模板', 2: '病历便签打印模板'};

@redux(_name, ['load', 'del'])
export default class Table1 extends React.Component {
    render() {
        const {data = []} = this.props;
        const treeData = data;//getTree();
        const columns = [{
            title: `${_title}名称`,
            dataIndex: 'Name'
        }, {
            title: '类型',
            dataIndex: 'Type',
            render: (val) => (types[val] || '')
        }, {
            title: '注释',
            dataIndex: 'Comment'
        }, {
            title: '状态',
            dataIndex: 'Status',
            render: yesRender
        }, {
            title: '操作',
            render: (val, data) => (
                <span>
                    <a className="blue" onClick={() => this.props.onState('edit', data)}>编辑</a>
                    <span className="ant-divider"/>
                    <Link to={`printTemplate/design/${data.Id}`}>编辑模板</Link>
                    <span className="ant-divider"/>
                    <a className="red">停用</a>
                </span>
            )
        }];
        setColumnKeys(columns);
        return (
            <div className="w100 padding-t">
                <Table
                    pagination={false}
                    columns={columns}
                    dataSource={treeData}
                    {...this.props}
                />
            </div>
        )
            ;
    }
}
